#!/usr/bin/perl -w
####################################################
# Copyright (c) 2002-2007 BioWare Corp.
# http://www.bigdaddymonitor.org
#
# This file is part of the BigDaddy Monitoring
# program. It is free software distributed under
# the terms of the BSD License. It is ditributed
# in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY; without event the implied
# warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# The BSD License is available from:
# http://www.opensource.org/licenses/bsd-license.php
####################################################
#=============================================================================#
#BigDaddy Module: Disk Space Check
#Author: Duleepa Wijayawardhana

#Date: 05.04.2004

#=============================================================================#



#!/usr/bin/perl -w
#=============================================================================#
#BigDaddy Module: Windows SNMP Hard Disk Capacity Check
#Author: Duleepa Wijayawardhana
#Date: 30.01.2005
#=============================================================================#

=intro

=cut

use strict;
use POSIX qw(ceil);
my ($sServer, $sLabel) = @ARGV;

my @aResults=`snmpwalk -c public -v 1 $sServer HOST-RESOURCES-MIB::hrStorage`;

my $sSearch;
my @aStorage;
my $nStorageDisk;
my $nStorageSize;
my $nStorageUsed;

foreach my $sLine (@aResults)
{
    if ($sLine =~ m/hrStorageDescr.([0-9]+) = STRING: ([0-9A-Za-z\/]+)/i)
    {
       
        if (lc($sLabel) eq lc($2))
        {
            $nStorageDisk=$1;
        }
    }
}

foreach my $sLine (@aResults)
{
    
    if ($sLine =~ m/hrStorageSize.$nStorageDisk = INTEGER: ([0-9]+)/i)
    {
        $nStorageSize=$1;
    }
    
    if ($sLine =~ m/hrStorageUsed.$nStorageDisk = INTEGER: ([0-9]+)/i)
    {
        $nStorageUsed=$1;
    }
    
}

my $nPercentUsed=ceil(($nStorageUsed/$nStorageSize)*100);
print $nPercentUsed;

